//
//  ZMEmotionViewCellButton.swift
//  ZMWeiboSwift
//
//  Created by pg on 2017/8/3.
//  Copyright © 2017年 pg. All rights reserved.
//

import UIKit

class ZMEmotionViewCellButton: UIButton {

    var emotionModel:ZMEmotionModel?{
        
        didSet{
            guard let currentEmotion = emotionModel else {
                return
            }
            
            
            //给按钮绑定数据显示按钮
            self.isHidden = false
            if currentEmotion.type == "0"{
                //  图片表情
                //  不能直接加载图片，因为图片在EmoitconBundle里面
                //  let image = UIImage(named: emoticon.png!)
                //  let path = HMEmoticonTools.sharedTools.emoticonBundle.resourcePath
                //  print(path)
                //  在指定bundle里面加载图片
                let image = UIImage(named: currentEmotion.path!, in: ZMEmotiontools.sharedTools.emotionBundle, compatibleWith: nil)
                self.setImage(image, for: .normal)
                self.setTitle(nil, for: .normal)
            } else {
                //  通过oc分类转成emoji表情
                let emoji = (currentEmotion.code! as NSString).emoji()
                self.setTitle(emoji, for: .normal)
                self.setImage(nil, for: .normal)
            }

            
            
            
        }
        
        
    }
}
